package com.ruoyi.mes.service.impl;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mes.utils.CodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mes.mapper.SleCustomerInfoMapper;
import com.ruoyi.mes.domain.SleCustomerInfo;
import com.ruoyi.mes.service.ISleCustomerInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 客户管理Service业务层处理
 * 
 * @author CFL
 * @date 2024-04-28
 */
@Service
public class SleCustomerInfoServiceImpl implements ISleCustomerInfoService 
{
    @Autowired
    private SleCustomerInfoMapper sleCustomerInfoMapper;


    /**
     * 查询客户管理
     * 
     * @param id 客户管理主键
     * @return 客户管理
     */
    @Override
    public SleCustomerInfo selectSleCustomerInfoById(Long id)
    {
        return sleCustomerInfoMapper.selectSleCustomerInfoById(id);
    }

    /**
     * 查询客户管理列表
     * 
     * @param sleCustomerInfo 客户管理
     * @return 客户管理
     */
    @Override
    public List<SleCustomerInfo> selectSleCustomerInfoList(SleCustomerInfo sleCustomerInfo)
    {
        return sleCustomerInfoMapper.selectSleCustomerInfoList(sleCustomerInfo);
    }

    /**
     * 新增客户管理
     * 
     * @param sleCustomerInfo 客户管理
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSleCustomerInfo(SleCustomerInfo sleCustomerInfo) {

        // 获取当前用户名
        BaseController username = new BaseController();
        String userName = username.getUsername();

        // 生成客户编号
        String customerSn = CodeUtils.CustomerCodeCreat();
        sleCustomerInfo.setCreatedBy(userName);
        sleCustomerInfo.setSn(customerSn);
        sleCustomerInfo.setCreatedTime(DateUtils.getNowDate());

        return sleCustomerInfoMapper.insertSleCustomerInfo(sleCustomerInfo);
    }


    /**
     * 修改客户管理
     * 
     * @param sleCustomerInfo 客户管理
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateSleCustomerInfo(SleCustomerInfo sleCustomerInfo) {
        // 获取当前用户名并设置创建人和创建时间
        BaseController username = new BaseController();
        String userName = username.getUsername();
        sleCustomerInfo.setCreatedBy(userName);
        sleCustomerInfo.setCreatedTime(DateUtils.getNowDate());
        return sleCustomerInfoMapper.updateSleCustomerInfo(sleCustomerInfo);
    }

    /**
     * 批量删除客户管理
     * 
     * @param ids 需要删除的客户管理主键
     * @return 结果
     */
    @Override
    public int deleteSleCustomerInfoByIds(Long[] ids)
    {
        return sleCustomerInfoMapper.deleteSleCustomerInfoByIds(ids);
    }

    /**
     * 删除客户管理信息
     * 
     * @param id 客户管理主键
     * @return 结果
     */
    @Override
    public int deleteSleCustomerInfoById(Long id)
    {
        return sleCustomerInfoMapper.deleteSleCustomerInfoById(id);
    }
}
